From: Keir Fraser Date: Tue, 3 Nov 2009 08:38:55 +0000 (+0000) Subject: Linux vbd hotplug: Avoid "leaked" loopback devices X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~13149 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22?a=commitdiff_plain;h=92e6cb5673b37bd883bdef0d0e83faf000edf61d;p=xen.git Linux vbd hotplug: Avoid "leaked" loopback devices Avoid races between hotplug "add" and "remove" leading to "leaked" loopback devices. - Don't setup loopback device if xend is no longer waiting for the vbd. - Use the lock file to avoid add/remove races. Signed-off-by: Gary Grebus --- diff --git a/tools/hotplug/Linux/block b/tools/hotplug/Linux/block index f50eeda563..171a4fca2a 100644 --- a/tools/hotplug/Linux/block +++ b/tools/hotplug/Linux/block @@ -233,6 +233,15 @@ case "$command" in claim_lock "block" + # Avoid a race with the remove if the path has been deleted, or + # otherwise changed from "InitWait" state e.g. due to a timeout + xenbus_state=$(xenstore_read_default "$XENBUS_PATH/state" 'unknown') + if [ "$xenbus_state" != '2' ] + then + release_lock "block" + fatal "Path closed or removed during hotplug add: $XENBUS_PATH state: $xenbus_state" + fi + if [ "$mode" = 'w' ] && ! stat "$file" -c %A | grep -q w then release_lock "block" @@ -363,8 +372,10 @@ mount it read-write in a guest domain." ;; file) + claim_lock "block" node=$(xenstore_read "$XENBUS_PATH/node") losetup -d "$node" + release_lock "block" exit 0 ;;